package test00.test05;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @Author lzp
 * @Date 2024-03-29
 */
public class People<P> {

    /**
     *  某个主人所养的宠物
     */
    private P pet;

    public P getPet() {
        return pet;
    }

    public void setPet(P pet) {
        this.pet = pet;
    }

    public void shopping()  {

        Class<?> aClass = pet.getClass();
        Field declaredField = null;
        try {
            declaredField = aClass.getDeclaredField("name");
            declaredField.setAccessible(true);
            Object name = declaredField.get(pet);
            System.out.println("我带着宠物"+name+"逛街");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }


        try {
            Method jiao = aClass.getDeclaredMethod("jiao");
            jiao.invoke(pet);
        } catch (Exception e) {
            throw new RuntimeException("不会叫"+e);
        }


    }

}
